<?php 
	namespace Admin\Controller;
	use Think\Controller;

	class UserController extends CommonController{
		public function index()
		{
			$userModel=D('user');
			//总条数
			$total=$userModel->count();
			//总页数
			$page=new \Think\Page($total,3);
			$page->setConfig('header','总页数');
			$page->setConfig('prev','上一页');
			$page->setConfig('next','下一页');
			//获取当前页
			$p=$page->nowPage;
			//echo $p;
			//exit;
			$page_str=$page->show();
			$limit=$page->firstRow.','.$page->listRows;

			$list=$userModel->getAll($limit);
			$this->assign('page',$page_str);
			$this->assign('p',$p);
			$this->assign('list',$list);
			$this->display();
		}
		public function change()
		{
			//接受当前页
			$p=$_GET['p'];
			//var_dump($p);exit;
			$where['id']=$_GET['id'];

			$model=M('user');
			//var_dump($status);
			$status=$model->where($where)->select();
			$data['status']=$status[0]['status']==0?1:0;
			//var_dump($data);
			$res=$model->where($where)->save($data);
			//var_dump($res);exit;
			if ($res) 
			{
				$this->redirect('User/index',['p'=>$p]);
			}
		}

		public function del()
		{
			//接受当前页
			$p=$_GET['p'];
			$id=$_GET['id'];

			$model=M('user');
			$res=$model->delete($id);
			if ($res) 
			{
				$this->redirect('User/index',['p'=>$p]);
			}
		}

		public function detail()
		{
			//接受当前页
			$p=$_GET['p'];
			$id=$_GET['id'];
			$model=D('user');

			$list=$model->getDetail($id);
			//var_dump($list);
			foreach ($list as $key => $value) 
			{
				$list[$key]['uiface']=$value['uiface']?'/Public/Uploads/'.$this->sub($value['uiface']).$value['uiface']:'/Public/Images/no.jpg';
				$list[$key]['uiname']=$value['uiname']=='xx'?'没有昵称':$value['uiname'];
				$list[$key]['uiage']=$value['uiage']?$value['uiage']:'还没有出生';
				$list[$key]['utime']=date('Y年m月d日',$value['utime']);
			}
			//var_dump($list);exit;
			//$list=$list[0];
			$this->assign('list',$list);
			$this->assign('p',$p);
			$this->display();
		}


		private function sub($str)
		{
			return substr($str, 0,4).'/'.substr($str, 4,2).'/'.substr($str, 6,2).'/';
		}
	}

?>